package com.lpssfxy.controller;

import com.lpssfxy.bean.R;
import com.lpssfxy.entity.User;
import com.lpssfxy.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"用户接口"})
@CrossOrigin(origins = "*", allowCredentials = "true")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param user
     * @return
     */
    @PostMapping("login")
    public R getUserById(@RequestBody User user){
        return userService.getUserByNameAndPwd(user);
    }

    /**
     * 注册
     * @param user
     * @return
     */
    @PostMapping("register")
    public R register(@RequestBody User user){
        return userService.addNewUser(user);
    }

    /**
     * 新增一批用户，用于后续联调测试
     * @return
     */
    @PostMapping("addBatchUsers")
    public R addBatchUsers(){
        return userService.addBatchUsers();
    }

    /**
     * 查询：获取所有用户列表
     * @return
     */
    @GetMapping("getUserList")
    public R getUserList(){
        return userService.getUserList();
    }

    /**
     * 更新：更新一个用户
     * @param user
     * @return
     */
    @PutMapping("updateUser")
    public R updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    /**
     * 删除：通过ID删除一个用户
     * @param userId
     * @return
     */
    @DeleteMapping("deleteUser/{userId}")
    public R deleteUser(@PathVariable Integer userId){
        return userService.deleteUser(userId);
    }
}
